﻿#region << 文 件 说 明 >>

/*----------------------------------------------------------------
// 文件名称：IDialogMessage
// 创 建 者：杨程
// 创建时间：2021/10/18 10:51:43
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//
//
//----------------------------------------------------------------*/

#endregion

namespace Vampirewal.Core.Interface;

/// <summary>
/// 事件聚合器
/// </summary>
public interface IVampirewalCoreEventAggregatorService
{
    /// <summary>
    /// 订阅事件（支持弱引用防止内存泄漏）
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="handler"></param>
    /// <param name="useWeakReference"></param>
    /// <returns></returns>
    SubscriptionToken Subscribe<T>(Action<T> handler, bool useWeakReference = true);

    /// <summary>
    /// 取消订阅（通过 Token 控制）
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="token"></param>
    void Unsubscribe<T>(SubscriptionToken token);

    /// <summary>
    /// 异步发布事件
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="message"></param>
    /// <param name="exception"></param>
    /// <returns></returns>
    Task PublishAsync<T>(T message, Action<Exception> exception = null);

    /// <summary>
    /// 同步发布事件
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="message"></param>
    /// <param name="exception"></param>
    void Publish<T>(T message, Action<Exception> exception = null);

    /// <summary>
    /// 事件过滤订阅（按条件筛选）
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="filter"></param>
    /// <param name="handler"></param>
    /// <returns></returns>
    SubscriptionToken SubscribeWithFilter<T>(Func<T, bool> filter, Action<T> handler);
}